// forgetpsw.js
var iconUrl = require('../../config.js').iconUrl;
var validata=require('../../utils/validata.js');

Page({

input:function(e){
     var key=e.currentTarget.id;
     var value=e.detail.value;
     this.setData({
       [key]:value
     });
},
  forgetpsw:function(){
    var mobile=this.data.mobile;
    var code = this.data.code;
    var psw = this.data.psw;
    var psw1 = this.data.psw1;
    validata.forget_psw(mobile, code, psw, psw1);    
  },
  get_code:function(e){
    var mobile=this.data.mobile;
    var that = this; 
    if (this.data.mobile.length !== 11) {
      validata.error_msg("电话号码格式错误");
      return;
    }    
    if (this.data.tapable) {       
      validata.get_code(mobile,2, function(){
        that._get_code(that);
      });
    }
    
  },
  _get_code: function (that){    
    var second = that.data.second;
    if (second == 0) {
      that.setData({ second: 60, textlable: "获取验证码", tapable: true });
      clearTimeout();
    } else {
      setTimeout(function () {
        second = second - 1;
        that.setData({ second: second, textlable: second + "s", tapable: false });
        that._get_code(that);
      }, 1000);
    }       
  },
  

  /**
   * 页面的初始数据
   */
  data: {
      iconUrl:iconUrl,
      mobile:'',
      code:'',
      real_code:'xxxx',
      psw:'',
      psw1:'',
      tapable:true,
      second:60,
      textlable:"获取验证码"
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})